package ken.app.even;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
import java.util.Map.Entry;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import ken.app.adapter.QueryPersonCouponAdapter;
import ken.app.bean.CHTContentUploadBean;
import ken.app.bean.GetCameraBabyBean;
import ken.app.bean.GetStoreInfoBean;
import ken.app.bean.GuestContentUploadBean;
import ken.app.bean.GuestRecordUploadBean;
import ken.app.bean.IndustryBabyBean;
import ken.app.bean.MemberContentUploadBean;
import ken.app.bean.MemberGoodBean;
import ken.app.bean.MemberModifyNameBean;
import ken.app.bean.MemberSelfGetFruitBean;
import ken.app.bean.NewsListBean;
import ken.app.bean.TranBabySaveCodeBean;
import ken.app.bean.PersonalBean;
import ken.app.bean.QueryMemberContentBean;
import ken.app.bean.QueryPersonCouponBean;
import ken.app.bean.QueryPersonalBabyBean;
import ken.app.bean.TranBabyGetCodeBean;
import ken.app.bean.SportBabyListBean;
import ken.app.bean.TreeAllBean;
import ken.app.bean.TreeSingleBean;
import ken.app.bean.UpdPushTokenBean;
import ken.app.bean.VisitorGoodBean;
import ken.app.comparator.BabyAllComparator;
import ken.app.comparator.StoreAllComparator;
import ken.app.comparator.TreeAllComparator;
import ken.app.even.iface.IEventCallback;
import ken.app.xmlhandler.CHTContentUploadXMLHandler;
import ken.app.xmlhandler.GetCameraBabyXMLHandler;
import ken.app.xmlhandler.GetStoreInfoXMLHandler;
import ken.app.xmlhandler.GuestContentUploadXMLHandler;
import ken.app.xmlhandler.GuestRecordUploadXMLHandler;
import ken.app.xmlhandler.IndustryBabyXMLHandler;
import ken.app.xmlhandler.LoginXMLHandler;
import ken.app.xmlhandler.MemberCanLikeXMLHandler;
import ken.app.xmlhandler.MemberContentUploadXMLHandler;
import ken.app.xmlhandler.MemberGoodXMLHandler;
import ken.app.xmlhandler.MemberModifyNameXMLHandler;
import ken.app.xmlhandler.MemberSelfGetFruitXMLHandler;
import ken.app.xmlhandler.NewsListXMLHandler;
import ken.app.xmlhandler.QueryMemberContentXMLHandler;
import ken.app.xmlhandler.QueryPerSorXMLHandler;
import ken.app.xmlhandler.QueryPersonCouponXMLHandler;
import ken.app.xmlhandler.QueryPersonalBabyXMLHandler;
import ken.app.xmlhandler.ServerTimeXMLHandler;
import ken.app.xmlhandler.ShareBabyListXMLHandler;
import ken.app.xmlhandler.SportBabyListXMLHandler;
import ken.app.xmlhandler.TranBabyGetCodeXMLHandler;
import ken.app.xmlhandler.TranBabySaveCodeXMLHandler;
import ken.app.xmlhandler.TreeAllXMLHandler;
import ken.app.xmlhandler.TreeSingleXMLHandler;
import ken.app.xmlhandler.UpdPushTokenXMLHandler;
import ken.app.xmlhandler.VisitorCanLikeXMLHandler;
import ken.app.xmlhandler.VisitorGoodXMLHandler;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import com.she.component.util.md5.MD5;
import com.she.olympic.Olympic;
import com.she.olympic.TreeActivity;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PermissionInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

public class KenEventManager {

//	private Handler mHandler = new Handler();
	
	// Keep Application Context
	private Context mContext = null;
	// Callback Registration Map
	private HashMap<String, List<IEventCallback>> mListenerMap  = new HashMap<String, List<IEventCallback>>();
	// 還有前置事項未完成的會進入Pending Map 
	private HashMap<String, Event> mPendingMap   = new HashMap<String, Event>();
	// 正在執行的會進入Executing Map
	private HashMap<String, Event> mExecutingMap = new HashMap<String, Event>();
	// Thread Pool
	private Executor mGeneralPool = Executors.newFixedThreadPool(50);

	
	/***************
	 * Constructor *
	 ***************/
	private KenEventManager() {}
	
	// Single Instance of EbookletEventManager
	private static KenEventManager mAPIManager = null;
	
	public static KenEventManager getInstance() {
		if(mAPIManager == null) mAPIManager = new KenEventManager();
		return mAPIManager;
	}
	
	// Should be called right after APIManager is created
	public void init(Context context) {
		if(mContext == null) mContext = context.getApplicationContext();
	}

		
	/********************
	 * Public Functions *
	 ********************/
	
	public boolean queryEvent(String signature) {
		if(mExecutingMap.containsKey(signature) || mPendingMap.containsKey(signature))
			return true;
		else
			return false;
	}
	
	public void registerListener(final String signature, final IEventCallback callback) {
		if(callback == null) return;
		mGeneralPool.execute(new Runnable() {
			@Override
			public void run() {
				synchronized(mListenerMap) {
					if(mListenerMap.containsKey(signature)) {
						// 有的話就把Callback List拿出來加進去
						mListenerMap.get(signature).add(callback);
					}
					else {
						// 沒有的話就新增進去Map
						List<IEventCallback> iCallbacks = new ArrayList<IEventCallback>();
						iCallbacks.add(callback);
						mListenerMap.put(signature, iCallbacks);
					}
				}
			}
		});
	}
	
	public void unregisterListener(final IEventCallback callback) {
		if(callback == null) return;
		mGeneralPool.execute(new Runnable() {
			@Override
			public void run() {
				synchronized(mListenerMap) {
					Iterator<Entry<String, List<IEventCallback>>> it = mListenerMap.entrySet().iterator();
					while(it.hasNext()) {
						// 把所有這個callback給移除
						List<IEventCallback> list = it.next().getValue();
						list.remove(callback);
					}
				}
			}
		});
	}
	
	public void cancel(final String signature) {
		mGeneralPool.execute(new Runnable() {
			@Override
			public void run() {
				synchronized(mPendingMap) {
					synchronized(mExecutingMap) {
						// 解除Pending裡的這個事件
						mPendingMap.remove(signature);
						// 解除Executing裡的這個事件
						mExecutingMap.remove(signature);
					}
				}
			}
		});
	}
	
	public void clearExecutingMap() {
		synchronized (mExecutingMap) {
			mExecutingMap.clear();
		}
	}
	
	public void execute(final Event event) {
		mGeneralPool.execute(new Runnable() {
			@Override
			public void run() {
				synchronized(mPendingMap) {
					synchronized(mExecutingMap) {
						if(mExecutingMap.containsKey(event.getSignature())) {
							// 如果ExecutingMap裡有 -> 把event融入ExecutingMap裡的該事件(event就可以不用理它了)
							Event executingEvent = mExecutingMap.get(event.getSignature());
							if(executingEvent != null) {
								// 把SubEvent黏上
								executingEvent.addSubEvents(event.getSubEvents());
								// 把Callback黏上
								executingEvent.addCallbacks(event.getCallbacks());
							}
						}
						else {
							// 如果PendingMap裡有
							if(mPendingMap.containsKey(event.getSignature())) {
								// 拿出來PendingMap裡的來Merge到自己
								Event pendingEvent = mPendingMap.get(event.getSignature());
								// 插入SubEvents
								event.addSubEvents(pendingEvent.getSubEvents());
								// 插入Callbacks
								event.addCallbacks(pendingEvent.getCallbacks());
								// PendingMap裡的就可以拿掉惹
								mPendingMap.remove(event.getSignature());
							} 
							// 把Event插到ExecutingMap裡
							mExecutingMap.put(event.getSignature(), event);
							
							/************************
							 * 根據是屬於哪一種Event去執行該事件的行為
							 * 例如 : 啟動連網Thread
							 * if(event instanceof DownloadEvent) {
									..........................................
									notifyResult(event, object, true, false);
							   }
							   else if(event instanceof DownloadImageEvent) {
							   		..........................................
							   		notifyResult(event, object, true, true);
							   else {
							   		notifyResult(event, null, true, false);
							   }
							 * **************************/
							
							/**加油樹event*/
							if (event instanceof GetTreeAllEvent) {
								
							    List<TreeAllBean> data=new ArrayList<TreeAllBean>();
							    try
							    {
							    	
//							    	String strResult="";
//							    	String urlString=((GetTreeAllEvent) event).getPath();
//
//										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
//							        	// 設定Timeout時間
//							        	conn.setConnectTimeout(1000);
//							        	conn.setReadTimeout(1000);
//							        	
//							        	conn.setRequestMethod("POST");
//							        	// Setup
//							        	conn.setUseCaches (false); 
//							        	conn.setDoOutput(true); 
//							        	conn.setDoInput(true);
//							        	/*輸入參數*/
//							        	OutputStream out = conn.getOutputStream(); 
//							        	/*tree_type=0是選手列婊*/
//							        	String strPostData ;
//							        	strPostData = "tree_type=0"+"&device=android&ver=" + TreeActivity.verCode;
//							        	
//							        	out.write(strPostData.getBytes());  
//							        	out.close(); 
//							        	Log.d("ken", "選手樹rs "+strPostData);
//							        	//当正确响应时处理数据
//							        	StringBuffer sb = new StringBuffer();
//							        	String readLine;
//							        	BufferedReader responseReader;
//							        	//处理响应流，必须与服务器响应流输出的编码一致
//							        	
//							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
//						    			String line = null; 
//						    			StringBuilder stringBuilder = new StringBuilder();
//						    			while((line = responseReader.readLine()) != null) {
//						    				stringBuilder.append(line);
//						    			}
//							        	strResult = stringBuilder.toString();
//							        	conn.disconnect();
//										
//							    	/* 產生SAXParser物件 */ 
//							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
//							    	SAXParser sp = spf.newSAXParser(); 
//							    	/* 產生XMLReader物件 */ 
//							    	XMLReader xr = sp.getXMLReader(); 
//							    	/* 設定自定義的MyHandler給XMLReader */ 
//							    	TreeAllXMLHandler myExampleHandler = new TreeAllXMLHandler(); 
//							    	xr.setContentHandler(myExampleHandler);     
//							    	/* 解析XML */
//							    	Log.d("ken", strResult);
//							    	xr.parse(new InputSource(new StringReader(strResult)));
//							    	/* 取得RSS標題與內容列表 */
//							    	data =myExampleHandler.getParsedData(); 
							    	
							    	data.add(new TreeAllBean(1, 1, 100, 200, "王大1", false, 0, 0, "123", 0));
							    	data.add(new TreeAllBean(1, 1, 100, 300, "王大2", false, 0, 0, "123", 0));
							    	data.add(new TreeAllBean(1, 1, 100, 11200, "王大3", false, 0, 0, "123", 0));
							    	data.add(new TreeAllBean(1, 1, 100, 4400, "王大4", false, 0, 0, "123", 0));
							    	data.add(new TreeAllBean(1, 1, 100, 99900, "王大5", false, 0, 0, "123", 0));
							      
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Toast.makeText(mContext, "網路為連接", 500).show();
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
//							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
////							      	((GetRssEvent) event).getActivity().finish();
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							    	
							      	notifyResult(event, "ERROR", false, false);
							     	Log.d("ken", "網路異常");
							    }
							}
							/**選手留言event*/
							if (event instanceof QueryTreeContentEvent) {
								
							    List<TreeSingleBean> data = new ArrayList<TreeSingleBean>();
							    try
							    {
//							    	String strResult="";					    	
//							    	String urlString=((QueryTreeContentEvent) event).getPath();
//
//										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
//							        	// 設定Timeout時間
//							        	conn.setConnectTimeout(1000);
//							        	conn.setReadTimeout(1000);
//							        	
//							        	conn.setRequestMethod("POST");
//							        	// Setup
//							        	conn.setUseCaches (false); 
//							        	conn.setDoOutput(true); 
//							        	conn.setDoInput(true);
//							        	/*輸入參數*/
//							        	OutputStream out = conn.getOutputStream(); 
//							        	/*tree_type=0是選手列婊*/
//							        	String strPostData = "tree_id="+ Integer.toString(((QueryTreeContentEvent) event).getTreeId())+"&device=android";
//							        	out.write(strPostData.getBytes());  
//							        	out.close(); 
//							        	
//							        	//当正确响应时处理数据
//							        	StringBuffer sb = new StringBuffer();
//							        	String readLine;
//							        	BufferedReader responseReader;
//							        	//处理响应流，必须与服务器响应流输出的编码一致
//							        	
//							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
//						    			String line = null; 
//						    			StringBuilder stringBuilder = new StringBuilder();
//						    			while((line = responseReader.readLine()) != null) {
//						    				stringBuilder.append(line);
//						    			}
//							        	strResult = stringBuilder.toString();
//							        	conn.disconnect();
//							        	Log.d("ken", "選手留言event "+strResult);
//							    	
//							    	/* 產生SAXParser物件 */ 
//							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
//							    	SAXParser sp = spf.newSAXParser(); 
//							    	/* 產生XMLReader物件 */ 
//							    	XMLReader xr = sp.getXMLReader(); 
//							    	/* 設定自定義的MyHandler給XMLReader */ 
//							    	TreeSingleXMLHandler myExampleHandler = new TreeSingleXMLHandler(); 
//							    	xr.setContentHandler(myExampleHandler);     
//							    	/* 解析XML */
//							    	xr.parse(new InputSource(new StringReader(strResult)));
//							    	/* 取得RSS標題與內容列表 */
//							    	data =myExampleHandler.getParsedData(); 
////							 	    title=myExampleHandler.getRssTitle();
////							    	((GetRssEvent) event).setTitle(myExampleHandler.getRssTitle());
//////									httpclient.getConnectionManager().shutdown();
////							    	Collections.sort(data, new RssComparator());
							      
							    	data.add(new TreeSingleBean(5, 99, 1, 11, "aa", 123, "加油", "加油123"));
							    	data.add(new TreeSingleBean(5, 99, 1, 11, "bb", 123, "加油", "加油123"));
							    	data.add(new TreeSingleBean(5, 99, 1, 11, "cc", 123, "加油", "加油123"));
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 

							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**登入event*/
							if (event instanceof LoginEvent) {
								
							    PersonalBean data ;
							    try
							    {
							    	String strResult="";
							    	String urlString=((LoginEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
//							        	conn.setRequestProperty("accept", "text/xml;text/html");
//							        	conn.setRequestProperty("Content-Type", "application/multipart/form-data");
//							        	conn.setRequestProperty("Content-Type","text/xml;charset=utf-8);
//							        	conn.addRequestProperty("username","stoutria@fakeinbox.com");
//							        	conn.addRequestProperty("password","000000");
//							        	conn.setRequestProperty("username","stoutria@fakeinbox.com");
//							        	conn.setRequestProperty("password","000000");
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	/*tree_type=0是選手列婊*/
							        	String strPostData = "username="+ PersonalBean.getInstance().getAccount() + "&" + "password="+ PersonalBean.getInstance().getPassword()+"&device=android";
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
//							        	StringBuffer sb = new StringBuffer();
//							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "login "+strResult);
//										String responseCookie = conn.getHeaderField("set-cookie");
//										if(responseCookie != null ) {
//											int index = responseCookie.indexOf(";");
//											if(index != -1) responseCookie = responseCookie.substring(0, index);
//											Log.d("ken", "cookie "+responseCookie);
////											setCookie(responseCookie);
//										}
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	LoginXMLHandler mLoginXMLHandler = new LoginXMLHandler(); 
							    	xr.setContentHandler(mLoginXMLHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =mLoginXMLHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Toast.makeText(mContext, "網路為連接", 500).show();
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							      	((GetRssEvent) event).getActivity().finish();
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, null, false, false);
							    }

							}
							
							/**個人樹查詢event*/
							if (event instanceof QueryPersonalScoreEvent) {
								
							    PersonalBean data ;
							    try
							    {
							    	String strResult="";
							    	String urlString=((QueryPersonalScoreEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
//							        	conn.setRequestProperty("accept", "text/xml;text/html");
//							        	conn.setRequestProperty("Content-Type", "application/multipart/form-data");
//							        	conn.setRequestProperty("Content-Type","text/xml;charset=utf-8);
//							        	conn.addRequestProperty("username","stoutria@fakeinbox.com");
//							        	conn.addRequestProperty("password","000000");
//							        	conn.setRequestProperty("username","stoutria@fakeinbox.com");
//							        	conn.setRequestProperty("password","000000");
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	/*tree_type=0是選手列婊*/
							        	PersonalBean personalInfo = PersonalBean.getInstance();
										Log.d("ken", "sn"+personalInfo.getChtsn());
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&check="+ genCheckCode(String.valueOf(PersonalBean.getInstance().getChtsn()))+"&device=android" ;
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
//							        	StringBuffer sb = new StringBuffer();
//							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "QueryPersonalScore  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	QueryPerSorXMLHandler mQueryPerSorXMLHandler = new QueryPerSorXMLHandler(); 
							    	xr.setContentHandler(mQueryPerSorXMLHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =mQueryPerSorXMLHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Toast.makeText(mContext, "網路為連接", 500).show();
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							      	((GetRssEvent) event).getActivity().finish();
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, null, false, false);
							    }

							}
							
							/**查詢會員留言event*/
							if (event instanceof QueryMemberContentEvent) {
								
							    List<QueryMemberContentBean> data = new ArrayList<QueryMemberContentBean>();
							    data.add(new QueryMemberContentBean(5, 5, 5, 5, "鍾阿憲", 1234567890, "殺呀~~!", "王建民"));
							    data.add(new QueryMemberContentBean(5, 5, 5, 5, "鍾阿憲", 1234567890, "三振他!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", "郭泓志"));
							    data.add(new QueryMemberContentBean(5, 5, 5, 5, "鍾阿憲", 1234567890, "大三元!!大三元!!大三元!!大三元!!大三元!!大三元!!", "林書豪"));
							    data.add(new QueryMemberContentBean(5, 5, 5, 5, "鍾阿憲", 1234567890, "打出去~打出去~打出去~打出去~", "陳金鋒"));
							    data.add(new QueryMemberContentBean(5, 5, 5, 5, "鍾阿憲", 1234567890, "全壘打~", "彭政閔"));
							    data.add(new QueryMemberContentBean(5, 5, 5, 5, "鍾阿憲", 1234567890, "..........", "Kobe"));
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((QueryMemberContentEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&check="+ genCheckCode(String.valueOf(PersonalBean.getInstance().getChtsn())) +"&device=android";
							        	Log.d("ken", "getChtsn "+PersonalBean.getInstance().getChtsn());
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "strResult"+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	QueryMemberContentXMLHandler myExampleHandler = new QueryMemberContentXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
//							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**採收果實event*/
							if (event instanceof CHTContentUploadEvent) {
								
							    CHTContentUploadBean data ;
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((CHTContentUploadEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	int treeid = ((CHTContentUploadEvent) event).getTreeId();
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&usertype=" + KenEventManager.getInstance().getUserType() + 
							        						"&tree_id=" + treeid + "&check="+ genCheckCode(String.valueOf(PersonalBean.getInstance().getChtsn())+treeid) +"&device=android";
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	Log.d("ken", "strPostData  "+strPostData+"--"+String.valueOf(PersonalBean.getInstance().getChtsn())+treeid);
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "CHTContentUploadEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	CHTContentUploadXMLHandler myExampleHandler = new CHTContentUploadXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
							    	Intent intent=new Intent();
							    	Bundle bundle = new Bundle();
							    	bundle.putString("error",""+e);
							    	intent.putExtras(bundle);
							    	/* 錯誤的回傳值設定為99 */
							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
							     	android.os.Process.killProcess(android.os.Process.myPid());
//							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**會員留言上傳event*/
							if (event instanceof MemberContentUploadEvent) {
								
							    MemberContentUploadBean data = new MemberContentUploadBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((MemberContentUploadEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	int treeid = ((MemberContentUploadEvent) event).getTreeId();
							        	String check = ""+PersonalBean.getInstance().getChtsn() +""+ treeid;
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&tree_id="+String.valueOf(treeid)+
							        			"&name="+((MemberContentUploadEvent) event).getName()+"&content="+((MemberContentUploadEvent) event).getContent()+"&game_code="+((MemberContentUploadEvent) event).getGameCode()+"&check="+genCheckCode(check)+"&device=android";
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "會員留言上傳rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "MemberContentUploadEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	MemberContentUploadXMLHandler myExampleHandler = new MemberContentUploadXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
//							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**會員按讚event*/
							if (event instanceof MemberGoodEvent) {
								
							    MemberGoodBean data = new MemberGoodBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((MemberGoodEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	int treeid = ((MemberGoodEvent) event).getTreeId();
							        	String check = ""+PersonalBean.getInstance().getChtsn() +""+ treeid;
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&tree_id="+String.valueOf(treeid)+"&game_code="+((MemberGoodEvent) event).getGameCode()+"&check="+genCheckCode(check)+"&name="+((MemberGoodEvent) event).getName()+"&device=android";
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "會員按讚rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "MemberGoodEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	MemberGoodXMLHandler myExampleHandler = new MemberGoodXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
//							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**修改個人樹名稱event*/
							if (event instanceof MemberModifyNameEvent) {
								
							    MemberModifyNameBean data = new MemberModifyNameBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((MemberModifyNameEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&member_name="+((MemberModifyNameEvent) event).getName()+"&check="+genCheckCode(String.valueOf(PersonalBean.getInstance().getChtsn()+"1"))+"&device=android";
							        	out.write(strPostData.getBytes());  
//							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "修改個人樹名稱rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "MemberModifyNameEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	MemberModifyNameXMLHandler myExampleHandler = new MemberModifyNameXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**個人優惠果實內容查詢event*/
							if (event instanceof QueryPersonCouponEvent) {
								
								List<QueryPersonCouponBean> data = new ArrayList<QueryPersonCouponBean>();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((QueryPersonCouponEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&check="+genCheckCode(String.valueOf(PersonalBean.getInstance().getChtsn()))+"&device=android";
							        	out.write(strPostData.getBytes());  
//							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "個人優惠果實內容查詢rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "QueryPersonCouponEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	QueryPersonCouponXMLHandler myExampleHandler = new QueryPersonCouponXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, data, false, false);
							    }
							}
							/**serveryTime查詢event*/
							if (event instanceof SeverTimeEvent) {
								
								long data = 0;
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((SeverTimeEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
//							        	OutputStream out = conn.getOutputStream(); 
//							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&check="+genCheckCode(String.valueOf(PersonalBean.getInstance().getChtsn()));
//							        	out.write(strPostData.getBytes());  
////							        	Log.d("ken", "check "+check);
//							        	Log.d("ken", "個人優惠果實內容查詢rs "+strPostData);
//							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "SeverTimeEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	ServerTimeXMLHandler myExampleHandler = new ServerTimeXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	if (data > 0) {
										long serverTime = (data * 1000) ; 
										long localTimeInGMT = new Date().getTime() + (new Date().getTimezoneOffset()*60*1000);
										long offset = serverTime-localTimeInGMT;
										setServerTimeOffset(offset);
									}
							    	
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**採收個人樹果實event*/
							if (event instanceof MemberSelfGetFruitEvent) {
								
							    MemberSelfGetFruitBean data = new MemberSelfGetFruitBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((MemberSelfGetFruitEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = "sn="+ String.valueOf(PersonalBean.getInstance().getChtsn()) + "&type=1&usertype=" + KenEventManager.getInstance().getUserType() + 
							        						 "&check="+ genCheckCode(String.valueOf(PersonalBean.getInstance().getChtsn())+1) +"&device=android";
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	Log.d("ken", "strPostData  "+strPostData+"--"+String.valueOf(PersonalBean.getInstance().getChtsn()));
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "MemberSelfGetFruitEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	MemberSelfGetFruitXMLHandler myExampleHandler = new MemberSelfGetFruitXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
//							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, data, false, false);
							    }
							}
							/**訪客留言上傳event*/
							if (event instanceof GuestContentUploadEvent) {
								
							    GuestContentUploadBean data = new GuestContentUploadBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((GuestContentUploadEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	int treeid = ((GuestContentUploadEvent) event).getTreeId();
							        	String check = String.valueOf(treeid)+((GuestContentUploadEvent) event).getMobile() ;
							        	String strPostData = "tree_id="+String.valueOf(treeid)+"&mobile="+((GuestContentUploadEvent) event).getMobile()+"&name="+((GuestContentUploadEvent) event).getName()+"&site="+((GuestContentUploadEvent) event).getSiteGuest()+"&game_code="+((GuestContentUploadEvent) event).getGameCode()+"&content="+((GuestContentUploadEvent) event).getContent()+"&check="+genCheckCode(check)+"&device=android";
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "訪客留言上傳rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "GuestContentUploadEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	GuestContentUploadXMLHandler myExampleHandler = new GuestContentUploadXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
//							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**訪客按讚event*/
							if (event instanceof VisitorGoodEvent) {
								
							    VisitorGoodBean data = new VisitorGoodBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((VisitorGoodEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	int treeid = ((VisitorGoodEvent) event).getTreeId();
							        	String check = String.valueOf(treeid)+((VisitorGoodEvent) event).getMobile() ;
							        	String strPostData = "tree_id="+String.valueOf(treeid)+"&mobile="+((VisitorGoodEvent) event).getMobile()+"&name="+((VisitorGoodEvent) event).getName()+"&site="+((VisitorGoodEvent) event).getSiteGuest()+"&game_code="+((VisitorGoodEvent) event).getGameCode()+"&check="+genCheckCode(check)+"&device=android";
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "訪客按讚rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "VisitorGoodEvent  "+strResult);
							        	conn.disconnect();
							    	
							    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	VisitorGoodXMLHandler myExampleHandler = new VisitorGoodXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							    	/* 發生錯誤時回傳result回上一個activity */
//							    	Intent intent=new Intent();
//							    	Bundle bundle = new Bundle();
//							    	bundle.putString("error",""+e);
//							    	intent.putExtras(bundle);
//							    	/* 錯誤的回傳值設定為99 */
//							    	((GetTreeAllEvent) event).getActivity().setResult(99, intent);
//							     	android.os.Process.killProcess(android.os.Process.myPid());
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**電信寶寶列表查詢event*/
							if (event instanceof SportBabyListEvent) {
								
								List<SportBabyListBean> data = new ArrayList<SportBabyListBean>();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((SportBabyListEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = "&device=android&ver=" + TreeActivity.verCode;
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "電信寶寶列表查詢rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "SportBabyListEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	SportBabyListXMLHandler myExampleHandler = new SportBabyListXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	Collections.sort(data, new BabyAllComparator());//距離排序
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, data, false, false);
							    }
							}
							/**會員寶寶列表查詢event*/
							if (event instanceof QueryPersonalBabyEvent) {
								
								List<QueryPersonalBabyBean> data = new ArrayList<QueryPersonalBabyBean>();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((QueryPersonalBabyEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = "sn=" + KenEventManager.getInstance().getCHTsn() + "&type=1&check=" + genCheckCode(String.valueOf(KenEventManager.getInstance().getCHTsn()) )+"&device=android&ver=" + TreeActivity.verCode;
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "會員電信寶寶列表查詢rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "QueryPersonalBabyEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	QueryPersonalBabyXMLHandler myExampleHandler = new QueryPersonalBabyXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, data, false, false);
							    }
							}
							/**可照集的寶寶列表查詢event*/
							if (event instanceof GetCameraBabyEvent) {
								
								List<GetCameraBabyBean> data = new ArrayList<GetCameraBabyBean>();
							    try
							    {
//							    	String strResult="";					    	
//							    	String urlString=((GetCameraBabyEvent) event).getPath();
//
//										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
//							        	// 設定Timeout時間
//							        	conn.setConnectTimeout(1000);
//							        	conn.setReadTimeout(1000);
//							        	conn.setRequestMethod("POST");
//							        	// Setup
//							        	conn.setUseCaches (false); 
//							        	conn.setDoOutput(true); 
//							        	conn.setDoInput(true);
//							        	/*輸入參數*/
//							        	OutputStream out = conn.getOutputStream(); 
//							        	String strPostData;
//							        	
//							        	double lat = 0;
//							        	double lng = 0;
//							        	if (((GetCameraBabyEvent) event).getLoc() != null) {
//							        		lat = ((GetCameraBabyEvent) event).getLoc().getLatitude();
//							        		lng = ((GetCameraBabyEvent) event).getLoc().getLongitude();
//										}
//							        	
//							        	if (getCHTsn() != 0) {
//							        		strPostData = "sn=" + getCHTsn() + "&type=1"+"&lat="+ lat +"&lng="+ lng +"&check="+genCheckCode("")+"&device=android&ver=" + TreeActivity.verCode;
//										}else{
//											strPostData = "check=" + genCheckCode("")+"&device=android&ver=" + TreeActivity.verCode;
//										}
//							        	
//							        	out.write(strPostData.getBytes());  
////							        	Log.d("ken", "check "+check);
//							        	Log.d("ken", "可照集的寶寶列表查詢rs "+strPostData);
//							        	out.close(); 
//							        	
//							        	//当正确响应时处理数据
//							        	StringBuffer sb = new StringBuffer();
//							        	String readLine;
//							        	BufferedReader responseReader;
//							        	//处理响应流，必须与服务器响应流输出的编码一致
//							        	
//							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
//						    			String line = null; 
//						    			StringBuilder stringBuilder = new StringBuilder();
//						    			while((line = responseReader.readLine()) != null) {
//						    				stringBuilder.append(line);
//						    			}
//							        	strResult = stringBuilder.toString();
//							        	Log.d("ken", "GetCameraBabyEvent  "+strResult);
//							        	conn.disconnect();
//							    								    	
//							    	/* 產生SAXParser物件 */ 
//							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
//							    	SAXParser sp = spf.newSAXParser(); 
//							    	/* 產生XMLReader物件 */ 
//							    	XMLReader xr = sp.getXMLReader(); 
//							    	/* 設定自定義的MyHandler給XMLReader */ 
//							    	GetCameraBabyXMLHandler myExampleHandler = new GetCameraBabyXMLHandler(); 
//							    	xr.setContentHandler(myExampleHandler);     
//							    	/* 解析XML */
//							    	xr.parse(new InputSource(new StringReader(strResult)));
//							    	/* 取得RSS標題與內容列表 */
//							    	data =myExampleHandler.getParsedData(); 
							    	data.add(new GetCameraBabyBean(1, "babyname", 123, 100, "camera_207_1", "camera_207_1", "camera_207_2", "camera_207_3", "camera_207_4", "camera_207_5", "camera_207_6", "camera_207_7", "camera_207_8", "camera_207_9", "camera_207_10", 1, "url", "typename", "1"));
							    	data.add(new GetCameraBabyBean(1, "babyname", 123, 100, "camera_207_1", "camera_207_1", "camera_207_2", "camera_207_3", "camera_207_4", "camera_207_5", "camera_207_6", "camera_207_7", "camera_207_8", "camera_207_9", "camera_207_10", 1, "url", "typename", "1"));
							    	data.add(new GetCameraBabyBean(1, "babyname", 123, 100, "camera_207_1", "camera_207_1", "camera_207_2", "camera_207_3", "camera_207_4", "camera_207_5", "camera_207_6", "camera_207_7", "camera_207_8", "camera_207_9", "camera_207_10", 1, "url", "typename", "1"));
							    	data.add(new GetCameraBabyBean(1, "babyname", 123, 100, "camera_207_1", "camera_207_1", "camera_207_2", "camera_207_3", "camera_207_4", "camera_207_5", "camera_207_6", "camera_207_7", "camera_207_8", "camera_207_9", "camera_207_10", 1, "url", "typename", "1"));
							    	data.add(new GetCameraBabyBean(1, "babyname", 123, 100, "camera_207_1", "camera_207_1", "camera_207_2", "camera_207_3", "camera_207_4", "camera_207_5", "camera_207_6", "camera_207_7", "camera_207_8", "camera_207_9", "camera_207_10", 1, "url", "typename", "1"));
							    	data.add(new GetCameraBabyBean(1, "babyname", 123, 100, "camera_207_1", "camera_207_1", "camera_207_2", "camera_207_3", "camera_207_4", "camera_207_5", "camera_207_6", "camera_207_7", "camera_207_8", "camera_207_9", "camera_207_10", 1, "url", "typename", "1"));
							    	data.add(new GetCameraBabyBean(1, "babyname", 123, 100, "camera_207_1", "camera_207_1", "camera_207_2", "camera_207_3", "camera_207_4", "camera_207_5", "camera_207_6", "camera_207_7", "camera_207_8", "camera_207_9", "camera_207_10", 1, "url", "typename", "1"));
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, "ERROR", false, false);
							     	Log.d("ken", "網路異常");
							    }
							}
							/**會員記錄電信寶寶event*/
							if (event instanceof GuestRecordUploadEvent) {
								
								GuestRecordUploadBean data = new GuestRecordUploadBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((GuestRecordUploadEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	int babyid = ((GuestRecordUploadEvent) event).getBabyId();
							        	String strPostData =  "baby_id="+ URLEncoder.encode(String.valueOf(babyid))+"&check=" + genCheckCode("")+"&device=android";
							        	
							        	out.write(strPostData.getBytes());  
//							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "會員記錄電信寶寶rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "GuestRecordUploadEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	GuestRecordUploadXMLHandler myExampleHandler = new GuestRecordUploadXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, data, false, false);
							    }
							}
							/**快訊資料查詢event*/
							if (event instanceof NewsListEvent) {
								
								List<NewsListBean> data = new ArrayList<NewsListBean>();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((NewsListEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	int tree_id = ((NewsListEvent) event).getTreeId();
							        	String strPostData = "tree_id="+ tree_id+"&device=android";
							        	
							        	out.write(strPostData.getBytes());  
//							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "快訊資料查詢查詢rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "newsListEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	NewsListXMLHandler myExampleHandler = new NewsListXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**推播event*/
							if (event instanceof UpdPushTokenEvent) {
								
								UpdPushTokenBean data ;
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((UpdPushTokenEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
//							        	String token = ((Olympic)mContext.getApplicationContext()).getRegistrationID();

							        	String token = ((UpdPushTokenEvent) event).getRegid();
							        	String strPostData = null;
							        	
							        	int sn;
							        	try {
							        		sn = getCHTsn();
										} catch (Exception e) {
											sn = 0;
										}
							        	String tokenold ;
							        	try {
							        		tokenold = ((Olympic)mContext.getApplicationContext()).getRegistrationID();
										} catch (Exception e) {
											tokenold = "";
										}
							        	
							        	
							        	if (((UpdPushTokenEvent) event).isPushIn() == true) {
							        		strPostData = "&device=android&token="+token +"&token_old="+tokenold+"&badge=0"+"&device=android";
										}else{
								        	if (sn != 0) {
								        		strPostData = "sn="+ getCHTsn() +"&device=android&token="+token +"&token_old="+ tokenold+"&device=android";
											}else{
												strPostData = "sn=&device=android&token="+token +"&token_old="+tokenold+"&device=android";
											}
										}
							        	
							        	out.write(strPostData.getBytes());  
//							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "推播rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "UpdPushTokenEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	UpdPushTokenXMLHandler myExampleHandler = new UpdPushTokenXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, null, false, false);
							    }
							}
							
							/**比對lastmodify*/
							if (event instanceof CheckBabyLastmodifyEvent) {
								Log.d("ken", "CheckBabyLastmodifyEvent  ");
							    try
							    {
									Bitmap bitmap;
									List<SportBabyListBean> babyListData = ((CheckBabyLastmodifyEvent)event).getBabyData();
									
									for (int i = 0; i < babyListData.size(); i++) {
										
										if (babyListData.get(i).getBabyId() == 101) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 201) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 202) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 203) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 204) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 205) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 206) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 207) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 208) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 209) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 210) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 211) {
											continue;
										}
										else if (babyListData.get(i).getBabyId() == 212) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 213) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 214) {
											continue;
										}else if (babyListData.get(i).getBabyId() == 215) {
											continue;
										}
										else if (babyListData.get(i).getBabyId() == 401) {
											continue;
										}
										
										if (getBabyLastmodify( String.valueOf(babyListData.get(i).getBabyId()) ) != babyListData.get(i).getLastmodify()) {
											
											ArrayList<String> paths = babyListData.get(i).getCameras();
											for (int j = 0; j < paths.size(); j++) {
												String iconName = null;
												try {
													URL mUrl = new URL(paths.get(j));
													URLConnection conn = mUrl.openConnection();
													conn.connect();
													InputStream isCover = conn.getInputStream();
													bitmap = BitmapFactory.decodeStream(isCover);
													isCover.close();
													
													//建立資料夾
													File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/.olympic/");
													if(!dir.exists()){
														dir.mkdirs();
													}
													iconName = paths.get(j).replaceAll(TreeActivity.SEVER_API+"/pic/baby/", "");
													iconName = iconName.replaceAll(TreeActivity.SEVER_API+"/pic/camera/", "");
													iconName = iconName.replaceAll("-", "_");
//													String iconName2 = iconName.replaceAll(".gif", "");
													FileOutputStream fout = new FileOutputStream("/sdcard/.olympic/" + iconName);
													bitmap.compress(Bitmap.CompressFormat.PNG, 100, fout);
													fout.close();
													
													/*下載完整記錄lastmodify*/
													if ( j == (paths.size()-1)) {
														setBabyLastmodify( String.valueOf(babyListData.get(i).getBabyId()) , babyListData.get(i).getLastmodify());
													}
													
												} catch (Exception e) {
													e.printStackTrace();
													Log.e("ken", iconName + "下載失敗");
													setBabyLastmodify( String.valueOf(babyListData.get(i).getBabyId()) , (long) 0);
													break;
												}
												
											}
										}
										
									}
							    	
							    	notifyResult(event, null, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, null, false, false);
							    }
								
							}
							
							/**分享加油寶寶event*/
							if (event instanceof TranBabyGetCodeEvent) {
								
								TranBabyGetCodeBean data = new TranBabyGetCodeBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((TranBabyGetCodeEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = null;
							        	int sn;
							        	sn = getCHTsn();
							        	strPostData = "device=android&type=1&sn="+ sn +"&baby_id="+((TranBabyGetCodeEvent) event).getBabyid()+"&check="+genCheckCode(String.valueOf(sn)+((TranBabyGetCodeEvent) event).getBabyid());
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "分享加油寶寶rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "ShareBabyEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	TranBabyGetCodeXMLHandler myExampleHandler = new TranBabyGetCodeXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/*獲取加油寶寶event*/
							if (event instanceof TranBabySaveCodeEvent) {
								
								TranBabySaveCodeBean data = new TranBabySaveCodeBean();
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((TranBabySaveCodeEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData = null;
							        	int sn;
							        	sn = getCHTsn();
							        	strPostData = "device=android&type=1&sn="+ sn +"&tran_code="+((TranBabySaveCodeEvent) event).getTrancode()+"&check="+genCheckCode(String.valueOf(sn) + ((TranBabySaveCodeEvent) event).getTrancode());
							        	out.write(strPostData.getBytes());  
							        	Log.d("ken", "獲取加油寶寶rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "ObtainBabyEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	TranBabySaveCodeXMLHandler myExampleHandler = new TranBabySaveCodeXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/*商家資訊event*/
							if (event instanceof GetStoreInfoEvent) {
								
								List<GetStoreInfoBean> data = new ArrayList<GetStoreInfoBean>();
								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 500, 1, 121.517448, 25.046458));
								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 300, 1, 121.518615, 25.040756));
								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 100, 1, 121.519236, 25.028645));
								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 400, 1, 121.535820, 25.012950));
								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 1000, 1, 121.514276, 25.047273));
//								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 20, 1, 121.537710, 25.052221));
//								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 5, 1, 121.520469, 25.062617));
//								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 90, 1, 121.544454, 25.052596));
//								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 770, 1, 121.529413, 25.026716));
								data.add(new GetStoreInfoBean("123", "滷肉飯", "https://www.google.com.tw/", 900, 1, 121.505282, 25.044975));
							    try
							    {
							    	String strResult="";					    	
							    	String urlString=((GetStoreInfoEvent) event).getPath();
//							    	String urlString="http://210.65.46.127/olympic/get_store_info";

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData;
							        	if (((GetStoreInfoEvent) event).getLoc() == null) {
							        		strPostData = "lng="+ 0 +"&lat="+ 0 +"&device=android";
										}else{
											strPostData = "lng="+ ((GetStoreInfoEvent) event).getLoc().getLongitude()+"&lat="+((GetStoreInfoEvent) event).getLoc().getLatitude()+"&device=android";
										}
							        	
							        	out.write(strPostData.getBytes());  
//							        	Log.d("ken", "check "+check);
							        	Log.d("ken", "商家資訊rs "+strPostData);
							        	out.close(); 
							        	
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	Log.d("ken", "GetStoreInfoEvent  "+strResult);
							        	conn.disconnect();
							    								    	
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	GetStoreInfoXMLHandler myExampleHandler = new GetStoreInfoXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data =myExampleHandler.getParsedData(); 
							    	
							    	Collections.sort(data, new StoreAllComparator());//距離排序
							    	
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    {
							      	notifyResult(event, data, false, false);
							    }
							}
							
							/**會員尚可加油event*/
							if (event instanceof MemberCanLikeEvent) {
								
							    List<TreeAllBean> data=new ArrayList<TreeAllBean>();
							    try
							    {
							    	String strResult="";
							    	String urlString=((MemberCanLikeEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	/*tree_type=0是選手列婊*/
							        	String strPostData ;
										strPostData = "type=1&sn=" + getCHTsn()+"&device=android&check=" + genCheckCode(getCHTsn()+"1");
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	Log.d("ken", "會員尚可加油rs "+strPostData);
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	conn.disconnect();
										
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	MemberCanLikeXMLHandler myExampleHandler = new MemberCanLikeXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	Log.d("ken", "MemberCanLikeEvent " + strResult);
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data = myExampleHandler.getParsedData(); 
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, "ERROR", false, false);
							     	Log.d("ken", "網路異常");
							    }
							}
							
							/**訪客尚可加油event*/
							if (event instanceof VisitorCanLikeEvent) {
								
							    List<TreeAllBean> data=new ArrayList<TreeAllBean>();
							    try
							    {
							    	String strResult="";
							    	String urlString=((VisitorCanLikeEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	/*tree_type=0是選手列婊*/
							        	String strPostData ;
										strPostData = "mobile=" + getGuestMobile()+"&device=android&check=" + genCheckCode(getGuestMobile());
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	Log.d("ken", "訪客尚可加油rs "+strPostData);
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	conn.disconnect();
										
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	VisitorCanLikeXMLHandler myExampleHandler = new VisitorCanLikeXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	Log.d("ken", "MemberCanLikeEvent " + strResult);
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data = myExampleHandler.getParsedData(); 
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, "ERROR", false, false);
							     	Log.d("ken", "網路異常");
							    }
							}
							
							/**可交換的加油寶寶event*/
							if (event instanceof ShareBabyListEvent) {
								
							    List<Integer> data=new ArrayList<Integer>();
							    try
							    {
							    	String strResult="";
							    	String urlString=((ShareBabyListEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	String strPostData ;
										strPostData = "device=android";
							        	
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	Log.d("ken", "可交換的加油寶寶rs "+strPostData);
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	conn.disconnect();
										
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	ShareBabyListXMLHandler myExampleHandler = new ShareBabyListXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	Log.d("ken", "MemberCanLikeEvent " + strResult);
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data = myExampleHandler.getParsedData(); 
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, data, false, false);
							     	Log.d("ken", "網路異常");
							    }
							}
							
							/**異業合作寶寶累加event*/
							if (event instanceof IndustryBabyEvent) {
								
							    IndustryBabyBean data= new IndustryBabyBean();
							    try
							    {
							    	String strResult="";
							    	String urlString=((IndustryBabyEvent) event).getPath();

										HttpURLConnection conn = (HttpURLConnection) new URL(urlString).openConnection();
							        	// 設定Timeout時間
							        	conn.setConnectTimeout(1000);
							        	conn.setReadTimeout(1000);
							        	
							        	conn.setRequestMethod("POST");
							        	// Setup
							        	conn.setUseCaches (false); 
							        	conn.setDoOutput(true); 
							        	conn.setDoInput(true);
							        	/*輸入參數*/
							        	OutputStream out = conn.getOutputStream(); 
							        	/*tree_type=0是選手列婊*/
							        	String strPostData ;
										strPostData = "type=1&sn=" + getCHTsn()+"&device=android&check=" + genCheckCode(getCHTsn()+"1")+"&baby_id=" + ((IndustryBabyEvent) event).getBabyid()+"&gift_product="+((IndustryBabyEvent) event).getGiftproduct();
							        	out.write(strPostData.getBytes());  
							        	out.close(); 
							        	Log.d("ken", "異業合作寶寶累加rs "+strPostData);
							        	//当正确响应时处理数据
							        	StringBuffer sb = new StringBuffer();
							        	String readLine;
							        	BufferedReader responseReader;
							        	//处理响应流，必须与服务器响应流输出的编码一致
							        	
							        	responseReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
						    			String line = null; 
						    			StringBuilder stringBuilder = new StringBuilder();
						    			while((line = responseReader.readLine()) != null) {
						    				stringBuilder.append(line);
						    			}
							        	strResult = stringBuilder.toString();
							        	conn.disconnect();
										
							    	/* 產生SAXParser物件 */ 
							    	SAXParserFactory spf = SAXParserFactory.newInstance(); 
							    	SAXParser sp = spf.newSAXParser(); 
							    	/* 產生XMLReader物件 */ 
							    	XMLReader xr = sp.getXMLReader(); 
							    	/* 設定自定義的MyHandler給XMLReader */ 
							    	IndustryBabyXMLHandler myExampleHandler = new IndustryBabyXMLHandler(); 
							    	xr.setContentHandler(myExampleHandler);     
							    	/* 解析XML */
							    	Log.d("ken", "IndustryBabyEvent " + strResult);
							    	xr.parse(new InputSource(new StringReader(strResult)));
							    	/* 取得RSS標題與內容列表 */
							    	data = myExampleHandler.getParsedData(); 
							    	notifyResult(event, data, true, false);
							    }
							    catch (Exception e)
							    { 
							      	notifyResult(event, data, false, false);
							     	Log.d("ken", "網路異常");
							    }
							}
							
//							if (event instanceof GetURLBitmapEvent) {
////								Bitmap[] bitmaps = new Bitmap [((GetURLBitmapEvent) event).getList().size()];
////								for (int i = 0; i < bitmaps.length; i++) {
////									try {
////										URL url = new URL(((GetURLBitmapEvent) event).getList().get(i).getImg());
////										URLConnection conn = url.openConnection();
////										conn.connect();
////										InputStream isCover = conn.getInputStream();
////										Bitmap bmpCover = BitmapFactory.decodeStream(isCover);
////										isCover.close();
////										bitmaps[i] = bmpCover;
////									} catch (Exception e) {
////										bitmaps[i] = null;
////									}
////								}
////								notifyResult(event, bitmaps, true, false);
//							}
						}
					}
				}
			}
		});	
	}
		
	void executeSubEvents(Event event) {
		List<Event> subEvents = event.getSubEvents();
		for(int i = 0; i < subEvents.size(); i++) {
			// execute本來就已經Thread化惹
			execute(subEvents.get(i));
		}
	}
											   /****/
	void notifyResult(final Event event, final Object connectionBean, boolean isSuccess, boolean isDownload) {
		// 執行黏在Event上的callback
		List<IEventCallback> callbacks = event.getCallbacks();
		for(int i = 0; i < callbacks.size(); i++) {
			final IEventCallback callback = callbacks.get(i);
			mGeneralPool.execute(new Runnable() {
				@Override
				public void run() {
					callback.result(event, connectionBean);
				}
			});
		}
		
		mGeneralPool.execute(new Runnable() {
			@Override
			public void run() {
				synchronized(mExecutingMap) {
				 	// 解除Executing裡的這個事件
					mExecutingMap.remove(event.getSignature());
				}
			}
		});
		
		if(isSuccess || isDownload) {
			// 通知所有有註冊這個事件的人
			synchronized(mListenerMap) {
				String signuture = event.getSignature();
				callbacks = mListenerMap.get(signuture);
				if(callbacks != null) {
					for(int i = 0; i < callbacks.size(); i++) {
						final IEventCallback callback = callbacks.get(i);
						mGeneralPool.execute(new Runnable() {
							@Override
							public void run() {
								callback.result(event, connectionBean);
							}
						});
					}
				}
				
				// 執行SubEvents
				executeSubEvents(event);
			}
		}
	}	
	
	void notifyProgress(final Event event, final int progress, final String tmpPath) {
		// 執行黏在Event上的callback
		List<IEventCallback> callbacks = event.getCallbacks();
		for(int i = 0; i < callbacks.size(); i++) {
			final IEventCallback callback = callbacks.get(i);
			mGeneralPool.execute(new Runnable() {
				@Override
				public void run() {
					callback.progress(event, progress, tmpPath);
				}
			});
		}
		
		// 通知所有有註冊這個事件的人
		mGeneralPool.execute(new Runnable() {
			@Override
			public void run() {
				synchronized(mListenerMap) {
					List<IEventCallback> callbacks = mListenerMap.get(event.getSignature());
					if(callbacks != null) {
						for(int i = 0; i < callbacks.size(); i++) {
							final IEventCallback callback = callbacks.get(i);
							mGeneralPool.execute(new Runnable() {
								@Override
								public void run() {
									callback.progress(event, progress, tmpPath);
								}
							});
						}
					}
				}
			}
		});
	}
	
	
	
	public String genCheckCode(String sn) {
		StringBuilder checkCode = new StringBuilder();
		// 設定時間格式&時區
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
		format.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
		// 設定MD5
		MD5 md5 = new MD5();
		try {
//			Calendar calendar =Calendar.getInstance();
//			String fullUrl = sn + format.format(calendar.getTime());
//			format.setTimeZone(TimeZone.getTimeZone("GMT"));
//			Date date = new Date(new Date().getTime() + EventManager.getInstance().getServerTimeOffset()); // 要加上ServerOffset
			long localTimeInGMT = new Date().getTime() + (new Date().getTimezoneOffset()*60*1000);
			Date date = new Date(localTimeInGMT + getServerTimeOffset()); // 要加上ServerOffset
			 
			String fullUrl = sn + format.format(date); 
			Log.d("ken", "localTimeInGMT"+format.format(date)+"getServerTimeOffset " + getServerTimeOffset());
			md5.Update(fullUrl, null);
			byte[] hash = md5.asHex().getBytes();
			// 取出特定的字元
			
			for (int i = 0; i < hash.length; i++) {
				checkCode.append((char)hash[i]);
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		// 回傳
		return checkCode.toString();
	}
	
	public String genCheckCodeForHead(String url) {
		StringBuilder checkCode = new StringBuilder();
		// 設定時間格式&時區
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
		format.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
		// 設定MD5
		MD5 md5 = new MD5();
		try {
//			format.setTimeZone(TimeZone.getTimeZone("GMT"));
//			Date date = new Date(new Date().getTime() + EventManager.getInstance().getServerTimeOffset()); // 要加上ServerOffset
			long localTimeInGMT = new Date().getTime() + (new Date().getTimezoneOffset()*60*1000);
			Date date = new Date(localTimeInGMT + getServerTimeOffset()); // 要加上ServerOffset
			String fullUrl = url + format.format(date); 
			md5.Update(fullUrl, null);
			byte[] hash = md5.asHex().getBytes();
			// 取出特定的字元
			checkCode.append((char)hash[4]);
			checkCode.append((char)hash[11]);
			checkCode.append((char)hash[2]);
			checkCode.append((char)hash[6]);
			checkCode.append((char)hash[8]);
			checkCode.append((char)hash[19]);
			checkCode.append((char)hash[12]);
			checkCode.append((char)hash[14]);
			checkCode.append((char)hash[6]);
			checkCode.append((char)hash[21]);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		// 回傳
		return checkCode.toString();
	}
	
	
	/*********************
	 * Private Functions *
	 *********************/
	
	public String getCookie() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getString("cookie", null);
	}
	
	public void setCookie(String cookie) {
		if(cookie != null && !cookie.equals("")) mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putString("cookie", cookie).commit();
		else mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().remove("cookie").commit();
	}
	
	public long getServerTimeOffset() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getLong("server_time_offset", 0);
	}
	
	public void setServerTimeOffset(long offset) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putLong("server_time_offset", offset).commit();
	}
	
	public int getCHTsn() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getInt("cht_sn", 0);
	}
	
	public void setCHTsn(int sn) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putInt("cht_sn", sn).commit();
	}
	
	public String getNICKName() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getString("nick_name", "null");
	}
	
	public void setNICKName(String nickname) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putString("nick_name", nickname).commit();
	}
	
	public String getAccount() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getString("Account", "null");
	}
	
	public void setAccount(String account) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putString("Account", account).commit();
	}
	
	public String getMembername() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getString("member_name", "null");
	}
	
	public void setMembername(String membername) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putString("member_name", membername).commit();
	}
	
	public int getUserType() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getInt("user_type", -1);
	}
	
	public void setUserType(int usertype) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putInt("user_type", usertype).commit();
	}
	
	public String getGuestMobile() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getString("guest_mobile", "null");
	}
	
	public void setGuestMobile(String guestmobile) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putString("guest_mobile", guestmobile).commit();
	}
	
	public String getGuestname() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getString("guest_name", "");
	}
	
	public void setGuestname(String Guestname) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putString("guest_name", Guestname).commit();
	}
	
	public boolean getFirstlogin() {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getBoolean("first_login", true);
	}
	
	public void setFirstlogin(boolean firstlogin) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putBoolean("first_login", firstlogin).commit();
	}
	
	public void setBabyLastmodify(String babyid , Long lastmodify) {
		mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).edit().putLong( babyid, lastmodify ).commit();
	}
	
	public long getBabyLastmodify(String babyid) {
		return mContext.getSharedPreferences("olympic", Context.MODE_PRIVATE).getLong( babyid, 0);
	}
}
